package com.danieldura.highrise.requests
{
	import com.danieldura.highrise.HighriseCredentials;
	import com.danieldura.highrise.data.Person;
	
	import flash.net.URLRequestMethod;
	
	public class PeopleRequest extends HighriseRequest
	{
		public function PeopleRequest( credentials:HighriseCredentials )
		{
			super( credentials, new HighriseRequestDataMap( "person", "people", Person ) );
		}
		
		public function listAll( offset:uint = 0 ):HighriseRequestToken
		{
			requestMethod = URLRequestMethod.GET;
			location = "/people" + format + "?n=" + offset;
			return send();
		}
		
		public function show( id:uint ):HighriseRequestToken
		{
			requestMethod = URLRequestMethod.GET;
			location = "/people/" + id + ".xml";
			return send();
		}
		
		public function listWithTitle( title:String, offset:uint = 0 ):HighriseRequestToken
		{
			requestMethod = URLRequestMethod.GET;
			location = "/people" + format + "?title=" + escape( title ) + "&n=" + offset;
			return send();
		}
		
		public function listWithTag( tagId:uint, offset:uint = 0 ):HighriseRequestToken
		{
			requestMethod = URLRequestMethod.GET;
			location = "/people" + format + "?tag_id=" + tagId + "&n=" + offset;
			return send();
		}
		
		public function listWithCompany( companyId:int, offset:int = 0 ):HighriseRequestToken
		{
			requestMethod = URLRequestMethod.GET;
			location = "/companies/" + companyId + "/people" + format + "?n=" + offset;
			return send();			
		}
		
		public function listBySearchTerm( searchTerm:String, offset:int = 0 ):HighriseRequestToken
		{
			requestMethod = URLRequestMethod.GET;
			location = "/people/search" + format + "?term=" + escape( searchTerm ) + "&n=" + offset;
			return send();
		}
		
		public function listSinceTime( dateTime:Date ):HighriseRequestToken
		{
			requestMethod = URLRequestMethod.GET;
			location = "people" + format + "?since" + encodeDate( dateTime );
			return send();
		}
		
		public function create( person:Person ):HighriseRequestToken
		{
			requestData = person.toXMLString();
			requestMethod = URLRequestMethod.POST;
			location = "/people.xml";
			return send();
		}
		
		public function update( person:Person ):HighriseRequestToken
		{
			requestData = person.toXMLString();
			requestMethod = "PUT";
			location = "/people/" + person.id + ".xml";
			return send();
		}
		
		public function destroy( person:Person ):HighriseRequestToken
		{
			requestMethod = "DELETE";
			location = "/people/" + person.id + ".xml";
			return send();
		}

	}
}